#include "MainMenuScene.h"
#include "GameScene.h"
using namespace cocos2d;

bool MainMenuScene::init()
{
	bool bRet = false;
	do
	{



	//CC_BREAK_IF(! CCScene::init());
	CCScene::init();
	//////////////////////////////////////////////////////////////////////////
	// super init first
	//////////////////////////////////////////////////////////////////////////

	m_layer = new CCLayer();
	CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
		"CloseNormal.png",
		"CloseSelected.png",
		this,
		menu_selector(MainMenuScene::menuEnterCallback));
	CC_BREAK_IF(! pCloseItem);

	// Place the menu item bottom-right conner.
	pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));

	// Create a menu with the "close" menu item, it's an auto release object.
	CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
	pMenu->setPosition(CCPointZero);
	CC_BREAK_IF(! pMenu);

	// Add the menu to HelloWorld layer as a child layer.
	m_layer->addChild(pMenu, 1);

	// 2. Add a label shows "Hello World".

	// Create a label and initialize with string "Hello World".
	CCLabelTTF* pLabel = CCLabelTTF::labelWithString("GAME TITLE", "Thonburi", 64);
	CC_BREAK_IF(! pLabel);

	// Get window size and place the label upper. 
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	pLabel->setPosition(ccp(size.width / 2, size.height - 20));

	// Add the label to HelloWorld layer as a child layer.
	m_layer->addChild(pLabel, 1);

	// 3. Add add a splash screen, show the cocos2d splash image.
	CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png");
	CC_BREAK_IF(! pSprite);

	// Place the sprite on the center of the screen
	pSprite->setPosition(ccp(size.width/2, size.height/2));

	// Add the sprite to HelloWorld layer as a child layer.
	m_layer->addChild(pSprite, 0);

	this->addChild(m_layer);
	bRet = true;
	}
	while (0);

	return bRet;
}

void MainMenuScene::menuEnterCallback( CCObject* pSender )
{
	CCScene* gs = GameLayer::scene();
	CCDirector::sharedDirector()->pushScene(gs);
}

MainMenuScene::MainMenuScene()
{
	init();
}